/**
 * 旅游包车分析
 */

var vehicle;
var enterprise;
$(function(){
	PlatformAnalyzes.init();
});

var PlatformAnalyzes = {
	param: {},
	init: function(){
		var me = this;
		me.initQueryTime();
		me.loadTableTitle();
		me.myChart=me.initBarChart();
		me.DoubleBarChart=me.initDoubleBarChart();
		me.PieChart=me.initPieChart();
		me.initPlatform();
		me.queryTable();
		me.initweek();
	},

//初始化时间
initQueryTime : function(){
    var todayDate = new Date();
    var todayDateStr=todayDate.getFullYear()+"-"+(todayDate.getMonth()+1)+"-"+todayDate.getDate();  
    var beforeDate = new Date(todayDate-86400000*1); //前一天
    var yyyy = beforeDate.getFullYear(), mm = (beforeDate.getMonth() + 1).toString(), dd = beforeDate.getDate().toString();
    if (mm.length == 1) {
        mm = '0' + mm;
    }
    if (dd.length == 1) {
        dd = '0' + dd;
    }
    $("#day").val(yyyy + '-' + mm + '-' + dd);
    beforeDate.setMonth(beforeDate.getMonth()-1);
    yyyy = beforeDate.getFullYear(), mm = (beforeDate.getMonth() + 1).toString();
    if (mm.length == 1) {
        mm = '0' + mm;
    }
    $("#month").val(yyyy + '-' + mm );
},
//初始化周维度
initweek : function(){
	$.ajax({
		type : 'post',
		url : appCtx + "base/report/PlatformAnalyzes/queryweek.html",
		cache : false,
		dataType : "JSON",
		success : function(data) {
			if(data!=null&&data!=''){
				$.each(data,function(entryIndex,entry) {
					$("#week").append("<option value='"+entry.value+"'>"+entry.text+"</option>");
				});				
			}
		}
	});
},
	
getColumn1:function(){
	return [{
        display : 'id',
        name : 'id',
        width : 0,
        hide : true,
    },{
        display : '平台名称',
        name : 'platform_name',
        width : 25,
        sortable : false,
        align : 'left'
    },{
        display : '归属单位',
        name : 'owner_unit',
        width : 30,
        sortable : false,
        align : 'left',
        showTitle : 'owner_unit'
    },{
        display : '断开次数',
        name : 'disconnect_count',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'disconnect_count'
    },{
        display : '在线总时长(分钟)',
        name : 'online_time',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'online_time',
        paramcolnames:['online_time'],
        handlefunction:function(paramcolnames){
        	var handleStr =Math.round((paramcolnames/60)*Math.pow(10,2))/Math.pow(10,2);	
    		return handleStr;
        }
    },{
        display : '连通率(%)',
        name : 'online_rate',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'online_rate',
        paramcolnames:['online_rate'],
        handlefunction:function(paramcolnames){
        	var handleStr =Math.round((paramcolnames)*Math.pow(10,2))/Math.pow(10,2);	
    		return handleStr;
        }
    }]
},
    
getColumn2:function(){
	return [{
        display : 'id',
        name : 'id',
        width : 0,
        hide : true,
    },{
        display : '平台名称',
        name : 'platform_name',
        width : 25,
        sortable : false,
        align : 'left',
        showTitle : 'platform_name'
    },{
        display : '车辆总数',
        name : 'vehicle_count',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'vehicle_count'
    },{
        display : '入网数',
        name : 'vehicle_access_count',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'vehicle_access_count'
    },{
        display : '入网率(%)',
        name : 'vehicle_access_rate',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'vehicleaccess_rate',
        paramcolnames:['vehicle_access_count','vehicle_count'],
        handlefunction:function(vehicle_access_count,vehicle_count){
        	var handleStr;
        	if(vehicle_access_count==0){
        		handleStr="0"
        	}else{
        		handleStr =Math.round((vehicle_access_count/vehicle_count*100)*Math.pow(10,2))/Math.pow(10,2);
        	}
    		return handleStr;
        } 	
    },{
        display : '上线数',
        name : 'vehicle_online_count',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'vehicle_online_count',
    },{
        display : '上线率(%)',
        name : 'vehicle_online_rate',
        width : 15,
        sortable : false,
        align : 'left',
        showTitle : 'vehicle_online_rate',
        paramcolnames:['vehicle_online_count','vehicle_access_count'],
        handlefunction:function(vehicle_online_count,vehicle_access_count){
        	var handleStr;
        	if(vehicle_access_count==0){
        		handleStr="0"
        	}else{
            	handleStr =Math.round((vehicle_online_count/vehicle_access_count*100)*Math.pow(10,2))/Math.pow(10,2);
        	}
    		return handleStr;
        }
    }]
},
    
getColumn3:function(){
	return [{
        display : '业户名称',
        name : 'platformName',
        width : 16,
        sortable : false,
        align : 'left',
        paramcolnames:['platformName'],
        handlefunction:function(platformName){
        	var handleStr = '';
        	if(platformName!=''){
        		handleStr="<span style='color:#2a5ab1;width:32%;font-weight:900;display:inline-block;' >"+platformName+"</span>";
        	}
    		return handleStr;
        }
    },{
        display : '班线客运',
        name : 'regularBus',
        width : 28,
        sortable : false,
        align : 'center',
        paramcolnames:['regularBus'],
        handlefunction:function(regularBus){
        	var handleStr="<span style='color:#27727b;width:32%;display:inline-block;' title='-' >-</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;' title='-' >-</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;' title='-' >-</span>";
        	if(regularBus!=''&&regularBus!=null&&regularBus!=undefined){
            	var arr = regularBus.split('|');
            	if(arr[0]=='车辆总数'){
            		handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' >"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>"+arr[2]+"</span>";
            	}else{
                	handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' title='车辆总数："+arr[0]+"'>"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'  title='入网数(率)："+arr[1]+"'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'  title='上线数(率)"+arr[2]+"'>"+arr[2]+"</span>";
            	}
        	}
    		return handleStr;
        }
    },{
        display : '旅游客运',
        name : 'touringCar',
        width : 28,
        sortable : false,
        align : 'center',
        paramcolnames:['touringCar'],
        handlefunction:function(touringCar){
        	var handleStr="<span style='color:#27727b;width:32%;display:inline-block;' title='-' >-</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;' title='-' >-</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;' title='-' >-</span>";
        	if(touringCar!=''&&touringCar!=null&&touringCar!=undefined){
            	var arr = touringCar.split('|');
            	if(arr[0]=='车辆总数'){
            		handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' >"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>"+arr[2]+"</span>";
            	}else{
                	handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' title='车辆总数："+arr[0]+"'>"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'  title='入网数(率)："+arr[1]+"'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'  title='上线数(率)"+arr[2]+"'>"+arr[2]+"</span>";
            	}
        	}
    		return handleStr;
        }
    },{
        display : '危运车辆',
        name : 'dangerCar',
        width : 28,
        sortable : false,
        align : 'center',
        paramcolnames:['dangerCar'],
        handlefunction:function(dangerCar){
        	var handleStr="<span style='color:#27727b;width:32%;display:inline-block;' title='-' >-</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;' title='-' >-</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;' title='-' >-</span>";
        	if(dangerCar!=''&&dangerCar!=null&&dangerCar!=undefined){
            	var arr = dangerCar.split('|');
            	if(arr[0]=='车辆总数'){
            		handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' >"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'>"+arr[2]+"</span>";
            	}else{
                	handleStr =	"<span style='color:#27727b;width:32%;display:inline-block;' title='车辆总数："+arr[0]+"'>"+arr[0]+"</span>|"+"<span style='color:#dc2727;width:32%;display:inline-block;'  title='入网数(率)："+arr[1]+"'>"+arr[1]+"</span>|"+"<span style='color:#27dc58;width:32%;display:inline-block;'  title='上线数(率)"+arr[2]+"'>"+arr[2]+"</span>";
            	}
        	}
    		return handleStr;
        }
    }]
},
getColumn4:function(){
	return [{
        display : '平台名称',
        name : 'platform_name',
        width : 19,
        sortable : false,
        align : 'left',
        showTitle : 'platform_name',
    },{
        display : '报警车辆数',
        name : 'alarm_vehicle_count',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'alarm_vehicle_count'
    },{
        display : '报警率(%)',
        name : 'alert_rate',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'alert_rate',
        paramcolnames:['alarm_vehicle_count','vehicle_access_count'],
        handlefunction:function(alarm_vehicle_count,vehicle_online_count){
        	var handleStr;
        	if(vehicle_online_count==0){
        		handleStr="0"
        	}else{
            	handleStr =Math.round((alarm_vehicle_count/vehicle_online_count)*10000)/100;
        	}
    		return handleStr;
        }
    },{
        display : '报警条数',
        name : 'alarm_count',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'alarm_count'
    },{
        display : '处理条数',
        name : 'alarm_processed',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'alarm_processed',
    },{
        display : '处警率(%)',
        name : 'alarm_processed_rate',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'alarm_processed_rate',
        paramcolnames:['alarm_processed','alarm_count'],
        handlefunction:function(alarm_processed,alarm_count){
        	var handleStr;
        	if(alarm_count==0){
        		handleStr="0"
        	}else{
            	handleStr =handleStr =Math.round(((alarm_processed/alarm_count)*100)*Math.pow(10,2))/Math.pow(10,2);
        	}
    		return handleStr;
        }
    },{
        display : '超速报警条数',
        name : 'overspeed_count',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'overspeed_count',
    },{
        display : '平均超速次数(次)',
        name : 'overspeed_count_avg',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'overspeed_count_avg',
        paramcolnames:['overspeed_count','vehicle_online_count'],
        handlefunction:function(overspeed_count,vehicle_online_count){
        	var handleStr
        	if(vehicle_online_count==0){
        		handleStr ="0";
        	}else{
        		handleStr = Math.round((overspeed_count/vehicle_online_count)*100)/Math.pow(10,2);
        	}
    		return handleStr;
        }
    },{
        display : '疲劳驾驶时长(分钟)',
        name : 'tired_duration',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'tired_duration',
        paramcolnames:['tired_duration'],
        handlefunction:function(tired_duration){
        	var handleStr;
        	handleStr =Math.floor(tired_duration/60);
    		return handleStr;
        }
    },{
        display : '平均疲劳驾驶时长(分钟)',
        name : 'outTime',
        width : 9,
        sortable : false,
        align : 'left',
        showTitle : 'outTime',
        paramcolnames:['tired_duration','vehicle_online_count'],
        handlefunction:function(tired_duration,vehicle_online_count){
        	var handleStr;
        	if(vehicle_online_count==0){
        		handleStr ="0";
        	}else{
        		handleStr =Math.round(((tired_duration/vehicle_online_count)/60)*Math.pow(10,2))/Math.pow(10,2);
        	}	
    		return handleStr;
        }
    }]
},
getColumn5:function(){   
	return [{
        display : 'id',
        name : 'id',
        width : 0,
        hide : true,
    },{
        display : '平台名称',
        name : 'platform_name',
        width : 30,
        sortable : false,
        align : 'left',
        showTitle : 'platform_name',
    },{
        display : '异常车辆数',
        name : 'exception_vehicle_count',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'exception_vehicle_count'
    },{
        display : '异常率(%)',
        name : 'exception_rate',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'exception_rate',
        paramcolnames:['exception_vehicle_count','vehicle_online_count'],
        handlefunction:function(exception_vehicle_count,vehicle_online_count){
        	var handleStr;
        	if(vehicle_online_count==0){
        		handleStr ="0";
        	}else{
        		handleStr =Math.round(((exception_vehicle_count/vehicle_online_count)*100)*Math.pow(10,2))/Math.pow(10,2);
        	}	
    		return handleStr;
        }
    },{
        display : '速度>160',
        name : 'speed_160_count',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'speed_160_count'
    },{
        display : '经纬度异常',
        name : 'location_exception_count',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'location_exception_count',
    },{
        display : '定位时间异常',
        name : 'gpstime_exception_count',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'gpstime_exception_count',
    },{
        display : '方向异常',
        name : 'head_exception_count',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'head_exception_count',
    }
    ,{
        display : '异常数据比率(%)',
        name : 'exception_contrast_rate',
        width : 10,
        sortable : false,
        align : 'left',
        showTitle : 'exception_contrast_rate',
        paramcolnames:['exception_track_count','track_normal'],
        handlefunction:function(exception_track_count,track_normal){
        	var handleStr;
        	if(track_normal+exception_track_count==0){
        		handleStr ="0";
        	}else{
        		handleStr = handleStr =Math.round(((exception_track_count/(Number(track_normal)+Number(exception_track_count)))*100)*Math.pow(10,2))/Math.pow(10,2);
        	}	
    		return handleStr;
        }
    }]
},
    
loadTableTitle:function(){
	$("#objTable1").flexigrid({
            dataType : 'json',
            colModel :this.getColumn1() ,
            usepager : false,// 是否分页，默认为true。
            height:240,
            singleSelect:true,
            widthType:'%',
            width:$('#chartMillage1').width(),
            rp : 100000,
            onSelectRow:function(row){
            	showShadowRegion(row.id,'BarChart',null);
            }
         });
	$("#objTable2").flexigrid({
        dataType : 'json',
        colModel :this.getColumn2() ,
        usepager : false,// 是否分页，默认为true。
        height:240,
        singleSelect:true,
        widthType:'%',
        width:$('#chartMillage2').width(),
        rp : 100000,
        onSelectRow:function(row){
        	showShadowRegion(row.id,null,'DoubleBarChart');
        }
     });
	$("#objTable3").flexigrid({
        dataType : 'json',
        colModel :this.getColumn3() ,
        usepager : false,// 是否分页，默认为true。
        singleSelect:true,
        height:240,
        widthType:'%',
        width:$('#chartMillage3').width(),
        rp : 100000
     });
	$("#objTable4").flexigrid({
        dataType : 'json',
        colModel :this.getColumn4() ,
        usepager : false,// 是否分页，默认为true。
        height:240,
        widthType:'%',
        width:$('#chartMillage4').width(),
        rp : 100000
     });
	$("#objTable5").flexigrid({
        dataType : 'json',
        colModel :this.getColumn5() ,
        usepager : false,// 是否分页，默认为true。
        height:240,
        singleSelect:true,
        widthType:'%',
        width:$('#chartMillage5').width(),
        rp : 100000,
        onSelectRow:function(row){
        	showpieChart(row);
        }
     });
},   
    
initBarChart: function(){
	var me = this;
	//计算显示的柱子数
	var percent = 100;
	option = {
	    tooltip : {
	        trigger: 'axis',
	        formatter: '{b0}<br />{a0}: {c0}%'
	    },
	    grid: {
	        left: '40px',
	        top:'40px',
	        right: '3px',
	        bottom:"10%",
//	        containLabel: true
	    },

	    calculable : true,
	    xAxis : [
	        {
	            type : 'category',
	            boundaryGap : false,
	            data : [],
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value',
	            name: '连通率',
	            min:0,
	            max:100,
	            axisLabel: {
	                formatter: '{value} %'
	            },
	            minInterval: 1,
	        }
	    ],
	    series : [
	        {
	            name:'连通率',
	            type:'line',
	            smooth:true,
	            itemStyle: {normal: {areaStyle: {type: 'default'}}},
	            data:[0],
	            areaStyle:{normal: {color:"#66CD00"}},
	            lineStyle:{normal: {color:"#00E5EE"}},
	        }
	    ]
	};
    var myChart = echarts.init(document.getElementById('barChart'));
    myChart.setOption(option);
    window.onresize = myChart.resize;
    return {
    	refash : function(option){
            myChart.setOption(option);
    	},
    	option : option,
    	barChartDom : myChart
    };        
},
	
initDoubleBarChart: function(){
	var me = this;
	option = {
	    tooltip: {
	        trigger: 'axis',
	        formatter: '{b0}<br />{a0}: {c0}%',
	        axisPointer: {
	            type: 'cross',
	            crossStyle: {
	                color: '#999'
	            }
	        }
	    },
	    legend: {
	        data:['入网率','上线率'],
	        top:'20px'
	    },
	    grid: {
	        left: '40px',
	        top:'40px',
	        right: '3px',
	        bottom:"10%",
//	        containLabel: true
	    },
	    xAxis: [
	        {
	            type: 'category',
	            data: [],
	            axisPointer: {
	                type: 'shadow'
	            }
	        }
	    ],
	    yAxis: [
	        {
	            type: 'value',
	            min: 0,
	            max: 100,
	            interval: 20,
	            axisLabel: {
	                formatter: '{value} %'
	            }
	        }
	    ],
	    series: [
	        {
	            name:'入网率',
	            type:'bar',   
	            barMaxWidth: '35px',
	            itemStyle: {normal: {color:'#27727b'}},
	            data:[]
	        },
	        {
	            name:'上线率',
	            type:'bar',
	            barMaxWidth: '35px',
	            itemStyle: {normal: {color:'#e87c25'}},
	            data:[]
	        }
	    ]
	};
    var mydoubleChart = echarts.init(document.getElementById('doubleBarChart'));
    mydoubleChart.setOption(option);
    window.onresize = mydoubleChart.resize;
    return {
    	refash : function(option){
    		mydoubleChart.setOption(option);
    	},
    	option : option,
    	doubleBarChart : mydoubleChart
    };        
},
	
initPieChart: function(){
	var me = this;
	option = {
	    grid:{
	    	top:0,
	    	bottom:0,
	    	right:0,
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        left: 'left',
	        data: []
	    },
	    series : [
	        {
	            name: '异常统计',
	            type: 'pie',
	            radius: ['45%', '75%'],
	            center: ['50%', '50%'],
	            avoidLabelOverlap: true,
	            label: {
	                normal: {
	                    show: true,
	                    formatter: '{b}',
	                    backgroundColor: '#eee',
	                    borderColor: '#aaa',
	                    borderWidth: 1,
	                    borderRadius: 4,
	                },
	                emphasis: {
	                    show: true,
	                    position:'inside',
	                    textStyle: {
	                        fontSize: '15',
	                        fontWeight: 'bold'
	                    }
	                }
	            },
	            labelLine: {
	                normal: {
	                    show: true,
	                },
	            },
	            data:[]
	        }
	    ],
		 color: ['rgb(249,124,37)','rgb(74,178,191)','rgb(134,218,179)','rgb(97,160,168)']
	};
	 var PieChart = echarts.init(document.getElementById('pieChart'));
	 PieChart.setOption(option);
	 window.onresize = PieChart.resize;
	 return {
	 	refash : function(option){
	 		PieChart.setOption(option);
	 	},
	 	option : option,
	 	pieChartDom : PieChart
	 };
},
	

initPlatform:function(){
	var platfromName = window.parent.platfromName;
	if(platfromName!=null&&''!= platfromName){
		$('#platform_id').html('<option>'+platfromName+'</option>');
	}
	
	$('#platform_id').select2({
		theme: "default",
	        allowClear: true,
	        placeholder: "请选择平台",
	        ajax:{
	            url: appCtx + "base/report/PlatformAnalyzes/queryPlatform.html",
	            dataType:"json",
	            delay:250,
	           async : true,
	            data:function(params){
	                return {
	                    name: params.term,
	                    page: params.page || 1
	                };
	            },
	            cache:true,
	            processResults: function (res, params) {
			    	if(res){
			    		var options = [];
			    		var option = {"id":" ", "text":"请选择平台"};
			    		options.push(option);
	    				$.each(res,function(index,obj) {
	    					var option = {"id":obj.gnss_centerid, "text":obj.text};
 	                    options.push(option);
	    				});
 	                return {
 	                	results: options,
 	                    pagination: {
 	                        more:false
 	                    }
 	                };
			    	}
	            },
	            escapeMarkup: function (markup) { return markup; },
	            minimumInputLength: 1
	        }
	})
	/*$.ajax({
		type : 'post',
		url : appCtx + "base/report/PlatformAnalyzes/queryPlatform.html",
		cache : false,
		dataType : "JSON",
		success : function(data) {
			if(data!=null&&data!=''){
				$('#vehicleSelDiv').html("<select class='query-select' id='platform_id'  onchange='cleanplatformId()' ></select>");
				var selectStr="";
				selectStr+="<option value=''>请选择平台</option>";
				$.each(data,function(entryIndex,entry) {
					if(platform_id==entry.gnss_centerid){
						selectStr+="<option value='"+entry.gnss_centerid+"'  selected='selected'>"+entry.text+"</option>";
					}else{
						selectStr+="<option value='"+entry.gnss_centerid+"'>"+entry.text+"</option>";
					}
				});
				$('#platform_id').html(selectStr);
				$("#platform_id").select2();					
			}
		}
	});*/
},

queryTable:function(){
	var veidoo = $("#veidoo").val();
	var analyse_date = null;
	var gnss_centerid = null;
	if(platform_id!=null&&platform_id!=''){
		gnss_centerid = platform_id;
	}else{
		gnss_centerid = $("#platform_id").val();
	}
	if(veidoo=='day'){
		analyse_date = $("#day").val();
	}else if(veidoo=='week'){
		analyse_date = $("#week").val();
	}else if(veidoo=='month'){
		analyse_date = $("#month").val();
	}
	var me = this;
	$.ajax({
		url:appCtx+"base/report/PlatformAnalyzes/queryPlatformAnalyzes.html",
		type:"post",
		data:{
			veidoo:veidoo,
			analyse_date:analyse_date,
			gnss_centerid:gnss_centerid
		},
		dataType:"json",
		success:function(data){
    		if(data.listAnalyzes.length==0){
				var dataRows= {
			     		rows:"",
			     		totol:0,
			     		page:1
			     	};
		     	$("#objTable1").flexAddData(dataRows);
		     	$("#objTable2").flexAddData(dataRows);
		     	$("#objTable3").flexAddData(dataRows);
		     	$("#objTable4").flexAddData(dataRows);
		     	$("#objTable5").flexAddData(dataRows);
		     	/*初始化饼图*/
		     	showpieChart('');
		     	showShadowRegion('','BarChart','DoubleBarChart');
			}else{
				/*给所有table赋值*/
		     	var dataRows= {
			     		rows:data.listAnalyzes,
			     		totol:data.listAnalyzes.length,
			     		page:1
			     	};
		     	var dataRows1= {
			     		rows:data.list,
			     		totol:data.list.length,
			     		page:1
			     	};
		     	$("#objTable1").flexAddData(dataRows);
		     	$("#objTable2").flexAddData(dataRows);
		     	$("#objTable3").flexAddData(dataRows1);
		     	$("#objTable4").flexAddData(dataRows);
		     	$("#objTable5").flexAddData(dataRows);
		     	/*初始化饼图*/
		     	showpieChart(data.listAnalyzes[0]);
		     	showShadowRegion(data.listAnalyzes[0].id,'BarChart','DoubleBarChart');
			}
		}
	});
},    
exportExcel : function(){
	var total = $("#objTable1").getOptions().total;
    if (total == 0) {
    	window.parent.global.ajaxLoading.pop("无导出数据", false, 2000);
        return;
    }
    //总记录数
    window.parent.global.ajaxLoading.pop("正在导出,请稍后.....", true, 2000);
	var me = this;
	var header1 = JSON.stringify(me.getColumn1());
	var header2 = JSON.stringify(me.getColumn2());
	var header3 = JSON.stringify(me.getColumn3());
	var header4 = JSON.stringify(me.getColumn4());
	var header5 = JSON.stringify(me.getColumn5());
	
	var headerbox1 = JSON.parse(header1);
	var headerbox2 = JSON.parse(header2);
	var headerbox3 = JSON.parse(header3);
	var headerbox4 = JSON.parse(header4);
	var headerbox5 = JSON.parse(header5);

	
	var headerWidth1 = $("#objTable1").width();
	for(var i=0;i<headerbox1.length;i++){
		headerbox1[i].width = Math.ceil(headerWidth1*1.5 / 100 * headerbox1[i].width);
	}
	var headerWidth2 = $("#objTable2").width();
	for(var i=0;i<headerbox2.length;i++){
		headerbox2[i].width = Math.ceil(headerWidth2*1.5 / 100 * headerbox2[i].width);
	}		
	var headerWidth3 = $("#objTable3").width();
	for(var i=0;i<headerbox3.length;i++){
		headerbox3[i].width = Math.ceil(headerWidth3 / 100 * headerbox3[i].width);
	}		
	var headerWidth4 = $("#objTable4").width();
	for(var i=0;i<headerbox4.length;i++){
		headerbox4[i].width = Math.ceil(headerWidth4 / 100 * headerbox4[i].width);
	}		
	var headerWidth5 = $("#objTable5").width();
	for(var i=0;i<headerbox5.length;i++){
		headerbox5[i].width = Math.ceil(headerWidth5*1.5 / 100 * headerbox5[i].width);
	}
	
	headerbox1.splice(headerbox1.length,1);
	headerbox2.splice(headerbox2.length,1);
	headerbox3.splice(headerbox3.length,1);
	headerbox4.splice(headerbox4.length,1);
	headerbox5.splice(headerbox5.length,1);
	

	var headerend1 = JSON.stringify(headerbox1);
	var headerend2 = JSON.stringify(headerbox2);
	var headerend3 = JSON.stringify(headerbox3);
	var headerend4 = JSON.stringify(headerbox4);
	var headerend5 = JSON.stringify(headerbox5);
	 var imageUrl = me.myChart.barChartDom.getDataURL({
		type: 'png',
	    pixelRatio: 1
	}); 
	 
	var imageUrl2 = me.DoubleBarChart.doubleBarChart.getDataURL({
			type: 'png',
		    pixelRatio: 1
	}); 
	 
	 var imageUrl3 = me.PieChart.pieChartDom.getDataURL({
			type: 'png',
		    pixelRatio: 1
	}); 
	 
	//表头
	var colModelList=new Array();
	colModelList.push(headerend1);
	colModelList.push(headerend2);
	colModelList.push(headerend3);
	colModelList.push(headerend4);
	colModelList.push(headerend5);
	var colModel= $.toJSON(colModelList);
	
	//图片
	var imgsrcList=new Array();
	imgsrcList.push(imageUrl);
	imgsrcList.push(imageUrl2);
	imgsrcList.push(imageUrl3);
	var imgsrc= $.toJSON(imgsrcList);
	var veidoo = $("#veidoo").val();
	var analyse_date = null;
	var gnss_centerid = null;
	if(platform_id!=null&&platform_id!=''){
		gnss_centerid = platform_id;
	}else{
		gnss_centerid = $("#platform_id").val();
	}
	if(veidoo=='day'){
		analyse_date = $("#day").val();
	}else if(veidoo=='week'){
		analyse_date = $("#week").val();
	}else if(veidoo=='month'){
		analyse_date = $("#month").val();
	}
	var sheetNames=["平台在线统计","平台车辆统计","平台行业统计","平台报警统计","平台异常统计"];
	var param =  {
		veidoo:veidoo,
		analyse_date:analyse_date,
		gnss_centerid:gnss_centerid,
		colModel:colModel,
		sheetNames:$.toJSON(sheetNames),
		title:"平台分析统计表",
		imgsrc:imgsrc
	};
	post(appCtx+"base/report/PlatformAnalyzes/export.html",param);
},

};
/**
 * 展示阴影图和柱状图
 */
function showShadowRegion(platform_id,BarChart,DoubleBarChart){
	var me = PlatformAnalyzes;
	var gnss_centerid=null;
	var veidoo = $("#veidoo").val();
	var analyse_date = null;
	if(platform_id!=null&&platform_id!=''){
		gnss_centerid = platform_id.split(":")[1];
	}
	if(veidoo=='day'){
		analyse_date = $("#day").val();
	}else if(veidoo=='week'){
		analyse_date = $("#week").val();
	}else if(veidoo=='month'){
		analyse_date = $("#month").val();
	}
	$.ajax({
		url:appCtx+"base/report/PlatformAnalyzes/showShadowRegion.html",
		type:"post",
		cache : false,
		data:{
			veidoo:veidoo,
			analyse_date:analyse_date,
			gnss_centerid:gnss_centerid,
		},
		dataType:"json",
		success:function(datas){
			if(BarChart=='BarChart'&&DoubleBarChart=='DoubleBarChart'){
				/*初始化阴影图*/
				var xis = new Array();
				var series = new  Array();
				var platformname=null;
				$.each(datas,function(index,vo){
					platformname=vo.platform_name;
					xis.push(global.getToday(vo.analyse_date).split(" ")[0]);
					series.push(vo.online_rate);
				});
				var options = me.myChart.option;
				options.xAxis[0].data=xis;
				options.series[0].data=series;
				me.myChart.refash(options);
				/*初始化条形图*/
				var xis = new Array();
				var series1 = new  Array();
				var series2 = new  Array();
				var platformname=null;
				$.each(datas,function(index,vo){
					xis.push(global.getToday(vo.analyse_date).split(" ")[0]);
					series1.push(Math.round((vo.vehicle_access_count/vo.vehicle_count*100)*Math.pow(10,2))/Math.pow(10,2));
					series2.push(Math.round((vo.vehicle_online_count/vo.vehicle_access_count*100)*Math.pow(10,2))/Math.pow(10,2));
				});
				var options = me.DoubleBarChart.option;
				options.xAxis[0].data=xis;
				options.series[0].data=series1;
				options.series[1].data=series2;
				me.DoubleBarChart.refash(options);   
			}else{
				if(BarChart=='BarChart'){
					var xis = new Array();
					var series = new  Array();
					var platformname=null;
					$.each(datas,function(index,vo){
						platformname=vo.platform_name;
						xis.push(global.getToday(vo.analyse_date).split(" ")[0]);
						series.push((vo.online_rate));
					});
					var options = me.myChart.option;
					options.xAxis[0].data=xis;
					options.series[0].data=series;
					me.myChart.refash(options);
				}
				if(DoubleBarChart=='DoubleBarChart'){
					var xis = new Array();
					var series1 = new  Array();
					var series2 = new  Array();
					var platformname=null;
					$.each(datas,function(index,vo){
						xis.push(global.getToday(vo.analyse_date).split(" ")[0]);
						series1.push(Math.round((vo.vehicle_access_count/vo.vehicle_count*100)*Math.pow(10,2))/Math.pow(10,2));
						series2.push(Math.round((vo.vehicle_online_count/vo.vehicle_access_count*100)*Math.pow(10,2))/Math.pow(10,2));
					});
					var options = me.DoubleBarChart.option;
					options.xAxis[0].data=xis;
					options.series[0].data=series1;
					options.series[1].data=series2;
					me.DoubleBarChart.refash(options);
				}
			}
		}
	});
}

function showpieChart(obj){
	var me = PlatformAnalyzes;
	var option = me.PieChart.option;
	var datas =new Array();
	var valueArr;
	$("#noData").remove();
	if(obj!=null&&obj!=""&&obj!=undefined){
		if(obj.gpstime_exception_count!=0||obj.location_exception_count!=0||obj.head_exception_count!=0||obj.speed_160_count!=0){
			valueArr = [obj.gpstime_exception_count,obj.location_exception_count,obj.head_exception_count,obj.speed_160_count];
			var nameArr = ['定位时间异常','经纬度异常','方向异常','速度>160'];
			for(var i=0;i<nameArr.length;i++){
				var map =new Object();
				map.name=nameArr[i];
				map.value=valueArr[i];
				datas.push(map);
			}
			option.legend.data=nameArr;
			option.series[0].data=datas;// [10, 52, 200, 334, 390, 330, 220];
			me.PieChart.refash(option);
		}else{
			global.noData("#pieChart");	
		}

	}else{
		global.noData("#pieChart");	
	}
}
function selectveidoo(){
	var vo = $("#veidoo").val();
	if(vo=='day'){
		$("#day").show();
		$("#week").hide();
		$("#month").hide();
	}else if(vo=='week'){
		$("#day").hide();
		$("#week").show();
		$("#month").hide();
	}else if(vo=='month'){
		$("#day").hide();
		$("#week").hide();
		$("#month").show();
	}
}
function cleanplatformId(){
	platform_id='';
}
function callback(veidoo,platform_id,analyse_date){
	$("#veidoo").val(veidoo);
	$("#platform_id").val(platform_id);
//	$("#platform_id").find("option[value='"+platform_id+"']").attr("selected",true);
	var name = $("#platform_id").find("option:selected").text();
	$("#select2-platform_id-container").text(name);
	if(veidoo=='day'){
		$("#day").show();
		$("#day").val(analyse_date);
		$("#week").hide();
		$("#month").hide();
	}else if(veidoo=='week'){
		$("#day").hide();
		$("#week").show();
		$("#week").val(analyse_date);
		$("#month").hide();
	}else if(veidoo=='month'){
		$("#day").hide();
		$("#week").hide();
		$("#month").show();
		$("#month").val(analyse_date);
	}
	PlatformAnalyzes.queryTable();
}